//
//  HotVC.m
//  MyStock
//
//  Created by 刘翔 on 2024/9/12.
//

#import "HotVC.h"
#import <TTGTags/TTGTagCollectionView.h>
#import "AppService.h"
#import "SeletedStockVC.h"
#import "CandidateStockVC.h"
#import "CostVC.h"


@interface HotVC ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>


@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *listVCArray;
@property (nonatomic, strong) JXCategoryListContainerView *listVCContainerView;
@property (nonatomic, strong) NSArray *titles;


@end

@implementation HotVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.customNavBar.title = @"屠龙刀";
    
    WeatherLabel *label = [[WeatherLabel alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    label.attributedText = [[NSAttributedString alloc] initWithString:[AppService shareInstance].weather];
    [self.customNavBar addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.customNavBar).offset(-10);
            make.right.equalTo(self.customNavBar).offset(-20);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(70);
    }];
    
    self.titles = @[@"精选池",@"候选池"];
    self.categoryView = [[JXCategoryTitleView alloc] init];
    self.categoryView.frame = CGRectMake(0, Height_NavBar, kScreenWidth,44);
    self.categoryView.delegate = self;
    self.categoryView.titles = self.titles;
    self.categoryView.titleColor = [UIColor colorWithHexString:@"#333333"];
    self.categoryView.titleSelectedColor = [UIColor colorWithHexString:@"#FB78A3"];
    self.categoryView.titleFont = [UIFont systemFontOfSize:14];
    self.categoryView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
    self.categoryView.defaultSelectedIndex = 0;
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.lineStyle = JXCategoryIndicatorLineStyle_Normal;
    lineView.lineScrollOffsetX = 5;
    lineView.indicatorColor = [UIColor colorWithHexString:@"#FB78A3"];
    self.categoryView.indicators = @[lineView];
    [self.view addSubview:self.categoryView];
    
    self.listVCContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    self.listVCContainerView.frame = CGRectMake(0, Height_NavBar + 44, kScreenWidth, kScreenHeight - Height_NavBar - Height_TabBar - 44);
    self.listVCContainerView.defaultSelectedIndex = 0;
    [self.view addSubview:self.listVCContainerView];
    
    self.categoryView.contentScrollView = self.listVCContainerView.scrollView;
  

    
    
    
    
//    [self.customNavBar wr_setRightButtonWithImage:[UIImage imageNamed:@"shuaxin"]];
//    [self.customNavBar wr_setRightButtonWithTitle:@"刷新" titleColor:Color_gray];
//    self.customNavBar.onClickRightButton = ^{
//        NSLog(@"刷新");
////        [self loadData];
//    };
    
  
    
//    [self loadData];
    
//    [self loadStocks];
//    [self loadCandidateStocks];

}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index
{
    
    [self.listVCContainerView didClickSelectedItemAtIndex:index];
        
}

//- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
//    [self.listVCContainerView didClickSelectedItemAtIndex:index];
//}
//
//- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
//
//
//    [self.listVCContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
//}

#pragma mark - JXCategoryListContainerViewDelegate

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    
    if (index == 0) {
        SeletedStockVC *vc = [[SeletedStockVC alloc] init];
        return vc;
    }else{
        
        CandidateStockVC *vc = [[CandidateStockVC alloc] init];
        return vc;
        
    }
    
}

- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}




- (IBAction)sendAC:(id)sender {
    
//    if (self.socketF.text.length > 0) {
//        [[AppService shareInstance].webSocket sendMsg:self.socketF.text];
//    }
}


- (void)loadStocks{
   
    BADataEntity *entity = [BADataEntity new];
    entity.urlString = [NSString stringWithFormat:@"%@/getstocks",MYSTOCKUrl];
    entity.needCache = NO;
    entity.parameters = nil;
    
    [MBProgressHUD showHUDAddedTo:lxWindow animated:YES];
    [BANetManager ba_request_GETWithEntity:entity successBlock:^(id response) {
        NSDictionary *result = response;
        if ([result[@"code"] intValue] == 1) {
            
            NSLog(@"%@",result);
         
            
        }
        
    } failureBlock:^(NSError *error) {
        
        
    } progressBlock:^(int64_t bytesProgress, int64_t totalBytesProgress) {
        
    }];
    
    
}

- (void)loadData{
    
    /*
     Date=2024-08-13&Index=0&Order=1&PhoneOSNew=2&Type=1&VerSion=5.15.0.3&ZSType=7&a=RealRankingInfo&apiv=w37&c=ZhiShuRanking&st=20
     Date=2024-08-13&Index=20&Order=1&PhoneOSNew=2&Type=1&VerSion=5.15.0.3&ZSType=7&a=RealRankingInfo&apiv=w37&c=ZhiShuRanking&st=2
     (
     ["801852"编号, "AI\u773c\u955c名字", 8381强度, 9.07, 0.028 涨速, 10334820142 成交额, -37831206主力净额, 828308761, -866139967, 5.163量比, 206469729792, 6.89, -27462600 300W打单净额, 251113156992, 3135354220第二季度机构增仓, 46.5017 2024年平均PE, 22.263 2025年平均PE, 8381, 9.07],)
     
     */
    NSString *dateStr = [[NSDate date] stringWithFormat:@"yyyy-MM-dd"];
    dateStr = @"2024-09-13";
    BADataEntity *entity = [BADataEntity new];
        entity.urlString = [NSString stringWithFormat:@"%@?%@",KPHotUrl,[NSString stringWithFormat:@"Date=%@&Index=20&Order=1&PhoneOSNew=2&Type=1&VerSion=5.15.0.3&ZSType=7&a=RealRankingInfo&apiv=w37&c=ZhiShuRanking&st=20",dateStr]];
    entity.needCache = NO;
    entity.parameters = nil;
    
    [MBProgressHUD showHUDAddedTo:lxWindow animated:YES];
    [BANetManager ba_request_GETWithEntity:entity successBlock:^(id response) {
        NSDictionary *result = response;
        if ([result[@"errcode"] intValue] == 0) {
            
//            self.hotgls = result[@"list"];
//            [self createTagViews];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        
    } progressBlock:^(int64_t bytesProgress, int64_t totalBytesProgress) {
        
    }];
}

@end
